package com.JZ.QM.scheduledTasksService;

import com.JZ.QM.feign.CombinationFeignService;
import com.JZ.QM.service.CombinationYieldService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author: cyc
 * @email cyc@gmail.com
 * @date: 2020/6/28 0:20
 */
@Service
public class ComShareDailyIncomeService {
    @Resource
    CombinationFeignService combinationFeignService;
    @Resource
    CombinationYieldService combinationYieldService;

    /**
     * 定时任务。每日更新原组合组合的收益
     */
    @Scheduled(cron="0 15 0 * * *")
    public void updateComYield(){
        //组合日收益更新的状态
        boolean combinationUpdateFlag=false;
        //声明当前的时间
        Date now = new Date();
        //定义时间的格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");//设置日期格式
        //定义日历时间
        Calendar c = Calendar.getInstance();
        //前一天时间
        Date start=new Date();
        //前一天日期格式转换
        String combinationUpdateDate="";

        c.add(Calendar.DATE, -1);
        start = c.getTime();
        combinationUpdateDate = dateFormat.format(start);
        //获取组合的更新状态
        combinationUpdateFlag=combinationYieldService.updateCombinationDailyIncomeRadio(combinationUpdateDate);
        if(combinationUpdateFlag){
            System.out.println("原组合已经更新完成");
        } else {
            System.out.println("原组合组合已经更新失败");
        }

    }
}
